package cn.edu.sdu.sduhour.controller;

import cn.edu.sdu.sduhour.entity.Tools;
import cn.edu.sdu.sduhour.mapper.ToolsMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/tools")
public class ToolsController {
    @Resource
    ToolsMapper toolsMapper;

    //查询此人所有的工具
    /*传入：String openid;*/
    @PostMapping("/all")
    public List<Tools> getAll(@RequestBody Tools tools) {
        return toolsMapper.findAll(tools);
    }

    //增加一条道具记录
    /*传入：String openid;*/
    @PostMapping("/add")
    public List<Tools> addOne(@RequestBody Tools tools) {
        toolsMapper.addOne(tools);
        return toolsMapper.findAll(tools);
    }

    //更改一条道具记录
    /*传入：
    * String changeName;
    * int changeNum;
    * String openid;
    * */
    @PostMapping("/set")
    public List<Tools> setOne(@RequestBody Tools tools) {
        toolsMapper.changeOne(tools);
        return toolsMapper.findAll(tools);
    }

    //删除一条道具记录（管理员）
    /*传入：int id;*/
    @DeleteMapping("/del")
    public String delOne(@RequestBody Tools tools) {
        toolsMapper.delOne(tools);
        return "success";
    }
}
